define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'basic/goods/index' + location.search,
                    add_url: 'basic/goods/add',
                    edit_url: 'basic/goods/edit',
                    del_url: 'basic/goods/del',
                    multi_url: 'basic/goods/multi',
                    import_url: 'basic/goods/import',
                    table: 'goods',
                    dragsort_url: "",
                },

                queryParams: function (params) { //自定义搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {}; //判断当前是否还有其他高级搜索栏的条件
                    var op = params.op ? JSON.parse(params.op) : {};  //并将搜索过滤器 转为对象方便我们追加条件
                    // if(Config.qty_yj){
                    //     filter.qty_yj= Config.qty_yj;     //将透传的参数 Config.qty_yj，追加到搜索条件中
                    //     op.qty_yj= "=";  //group_id的操作方法的为 找到相等的
                    // }

                    params.filter = JSON.stringify(filter); //将搜索过滤器和操作方法 都转为JSON字符串
                    params.op = JSON.stringify(op);
                    //如果希望忽略搜索栏搜索条件,可使用
                    //params.filter = JSON.stringify({url: 'login'});
                    //params.op = JSON.stringify({url: 'like'});
                    return params;

                },
            });

            var table = $("#table");


            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'category_id', title: __('商品类'),
                            searchList: $.getJSON("basic/goods/getCategory")
                        },
                        {field: 'unit', title: __('单位'), operate: false},
                        {field: 'number', title: __('Number'), operate: 'LIKE'},
                        {
                            field: 'spell',
                            title: __('Spell'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {field: 'qty', title: __('剩余库存'), operate: false},
                        {field: 'cost_price', title: __('成本价'), operate: false},
                        {field: 'retail_price', title: __('Retail_price'), operate: false},
                        // {field: 'min_price', title: __('Min_price'), operate: false},
                        // {field: 'pre_price_a', title: __('Pre_price_a'), operate: false},
                        // {field: 'pre_price_b', title: __('Pre_price_b'), operate: false},
                        {
                            field: 'bar_code',
                            title: __('Bar_code'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'sku',
                            title: __('Sku'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'model_number',
                            title: __('Model_number'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'remarks',
                            title: __('Remarks'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        //    {field: 'weigh', title: __('Weigh'), operate: false},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'qty_yj', title: __('预警商品'),
                            searchList: {
                                "100": __('未预警'),
                                "200": __('预警'),
                            }, formatter: Table.api.formatter.status,
                            defaultValue: Config.qty_yj,
                            visible: false

                        },
                        //   {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('库存记录'),
                                    title: __('库存记录'),
                                    extend: 'data-area=["95%","95%"]',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'basic/goods/qty_log',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        sales_list: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'basic/goods/sales_list' + location.search,
                    add_url: 'basic/goods/add',
                    // edit_url: 'basic/goods/edit',
                    // del_url: 'basic/goods/del',
                    multi_url: 'basic/goods/multi',
                    import_url: 'basic/goods/import',
                    table: 'goods',
                    dragsort_url: "",
                }
            });

            var table = $("#table");
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);

                $("input[name='unit_id']", form).addClass("selectpage").data("source", "basic/unit/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                // $("input[name='stash_id']", form).addClass("selectpage").data("source", "basic/stash/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                $("input[name='staff_id']", form).addClass("selectpage").data("source", "basic/staff/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                // $("input[name='assets_id']", form).addClass("selectpage").data("source", "basic/assets/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible: true,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'number', title: __('商品编号'), operate: 'LIKE'},
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'category_id', title: __('商品类'),
                            searchList: $.getJSON("basic/goods/getCategory")
                        },
                        {field: 'unit', title: __('单位'), operate: false,},
                        {field: 'staff_id', title: __('经手人'), visible: false,},
                        {field: 'unit_id', title: __('往来单位'), visible: false,},

                        {field: 'qty', title: __('销售数量'), operate: false},
                        {field: 'amount', title: __('销售金额'), operate: false},
                        {field: 'cost_amount', title: __('成本金额'), operate: false},
                        {field: 'ml_amount', title: __('毛利'), operate: false},
                        {field: 'ml_rate', title: __('毛利率(%)'), operate: false},
                        {
                            field: 'date',
                            title: __('时间查询'),
                            align: 'center',
                            formatter: Table.api.formatter.datetime,
                            defaultValue: this.getFirstDayOfMonth() + " 00:00:00 - " + this.getLastDayOfMonth() + ' 23:59:59',
                            operate: 'RANGE',
                            visible: false,
                            addclass: 'datetimerange'
                        }

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        restock_list: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'basic/goods/restock_list' + location.search,
                    add_url: 'basic/goods/add',
                    // edit_url: 'basic/goods/edit',
                    // del_url: 'basic/goods/del',
                    multi_url: 'basic/goods/multi',
                    import_url: 'basic/goods/import',
                    table: 'goods',
                    dragsort_url: "",
                }
            });

            var table = $("#table");
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);

                $("input[name='unit_id']", form).addClass("selectpage").data("source", "basic/unit/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                // $("input[name='stash_id']", form).addClass("selectpage").data("source", "basic/stash/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                $("input[name='staff_id']", form).addClass("selectpage").data("source", "basic/staff/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                // $("input[name='assets_id']", form).addClass("selectpage").data("source", "basic/assets/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible: true,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'number', title: __('商品编号'), operate: 'LIKE'},
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'category_id', title: __('商品类'),
                            searchList: $.getJSON("basic/goods/getCategory")
                        },
                        {field: 'unit', title: __('单位'), operate: false,},
                        {field: 'staff_id', title: __('经手人'), visible: false,},
                        {field: 'unit_id', title: __('往来单位'), visible: false,},

                        {field: 'jh_qty', title: __('进货数量'), operate: false},
                        {field: 'jh_amount', title: __('进货金额'), operate: false},
                        {field: 'th_qty', title: __('退货数量'), operate: false},
                        {field: 'th_amount', title: __('退货金额'), operate: false},
                        {field: 'real_qty', title: __('实际进货数量'), operate: false},
                        {field: 'real_amount', title: __('实际进货金额'), operate: false},
                        {
                            field: 'date',
                            title: __('时间查询'),
                            align: 'center',
                            formatter: Table.api.formatter.datetime,
                            defaultValue: this.getFirstDayOfMonth() + " 00:00:00 - " + this.getLastDayOfMonth() + ' 23:59:59',
                            operate: 'RANGE',
                            visible: false,
                            addclass: 'datetimerange'
                        }

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        inventory: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'basic/goods/inventory' + location.search,
                    add_url: 'basic/goods/add',
                    // edit_url: 'basic/goods/edit',
                    // del_url: 'basic/goods/del',
                    multi_url: 'basic/goods/multi',
                    import_url: 'basic/goods/import',
                    table: 'goods',
                    dragsort_url: "",
                }
            });

            var table = $("#table");
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);

                // $("input[name='unit_id']", form).addClass("selectpage").data("source", "basic/unit/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                $("input[name='stash_id']", form).addClass("selectpage").data("source", "basic/stash/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                // $("input[name='staff_id']", form).addClass("selectpage").data("source", "basic/staff/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                // $("input[name='assets_id']", form).addClass("selectpage").data("source", "basic/assets/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible: true,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'number', title: __('商品编号'), operate: 'LIKE'},
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'category_id', title: __('商品类'),
                            searchList: $.getJSON("basic/goods/getCategory")
                        },
                        {field: 'unit', title: __('单位'), operate: false,},

                        {field: 'cost_price', title: __('成本价'), operate: false},
                        {field: 'retail_price', title: __('零售价'), operate: false},
                        {field: 'surplus_qty', title: __('库存数量'), operate: false,},
                        {field: 'sum_cost_amount', title: __('库存金额'), operate: false},
                        {field: 'stash_id', title: __('仓库'), visible: false,operate: false},


                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        other_warehousing: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'basic/goods/other_warehousing' + location.search,
                    add_url: 'basic/goods/add',
                    // edit_url: 'basic/goods/edit',
                    // del_url: 'basic/goods/del',
                    multi_url: 'basic/goods/multi',
                    import_url: 'basic/goods/import',
                    table: 'goods',
                    dragsort_url: "",
                }
            });

            var table = $("#table");
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);

                $("input[name='unit_id']", form).addClass("selectpage").data("source", "basic/unit/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                $("input[name='stash_id']", form).addClass("selectpage").data("source", "basic/stash/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                $("input[name='staff_id']", form).addClass("selectpage").data("source", "basic/staff/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                // $("input[name='assets_id']", form).addClass("selectpage").data("source", "basic/assets/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible: true,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'number', title: __('商品编号'), operate: 'LIKE'},
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'category_id', title: __('商品类'),
                            searchList: $.getJSON("basic/goods/getCategory")
                        },
                        {
                            field: 'type', title: __('入库类型'),
                            searchList: $.getJSON("category/getRk"),
                            visible: false,
                        },
                        {field: 'unit', title: __('单位'), operate: false,},

                        {field: 'qty', title: __('数量'), operate: false},
                        {field: 'avg_price', title: __('均价'), operate: false},
                        {field: 'sum_price', title: __('金额'), operate: false,},

                        {field: 'stash_id', title: __('仓库'), visible: false},
                        {field: 'unit_id', title: __('来往单位'), visible: false},
                        {field: 'staff_id', title: __('经手人'), visible: false},
                        {
                            field: 'date',
                            title: __('时间查询'),
                            align: 'center',
                            formatter: Table.api.formatter.datetime,
                            defaultValue: this.getFirstDayOfMonth() + " 00:00:00 - " + this.getLastDayOfMonth() + ' 23:59:59',
                            operate: 'RANGE',
                            visible: false,
                            addclass: 'datetimerange'
                        }

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        other_outbound: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'basic/goods/other_outbound' + location.search,
                    add_url: 'basic/goods/add',
                    // edit_url: 'basic/goods/edit',
                    // del_url: 'basic/goods/del',
                    multi_url: 'basic/goods/multi',
                    import_url: 'basic/goods/import',
                    table: 'goods',
                    dragsort_url: "",
                }
            });

            var table = $("#table");
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);

                $("input[name='unit_id']", form).addClass("selectpage").data("source", "basic/unit/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                $("input[name='stash_id']", form).addClass("selectpage").data("source", "basic/stash/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                $("input[name='staff_id']", form).addClass("selectpage").data("source", "basic/staff/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                // $("input[name='assets_id']", form).addClass("selectpage").data("source", "basic/assets/index").data("primaryKey", "id").data("field", "name").data("orderBy", "id desc");

                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible: true,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'number', title: __('商品编号'), operate: 'LIKE'},
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'category_id', title: __('商品类'),
                            searchList: $.getJSON("basic/goods/getCategory")
                        },
                        {
                            field: 'type', title: __('出库类型'),
                            searchList: $.getJSON("category/getCk"),
                            visible: false,
                        },
                        {field: 'unit', title: __('单位'), operate: false,},

                        {field: 'qty', title: __('数量'), operate: false},
                        {field: 'avg_price', title: __('均价'), operate: false},
                        {field: 'sum_price', title: __('金额'), operate: false,},

                        {field: 'stash_id', title: __('仓库'), visible: false},
                        {field: 'unit_id', title: __('来往单位'), visible: false},
                        {field: 'staff_id', title: __('经手人'), visible: false},
                        {
                            field: 'date',
                            title: __('时间查询'),
                            align: 'center',
                            formatter: Table.api.formatter.datetime,
                            defaultValue: this.getFirstDayOfMonth() + " 00:00:00 - " + this.getLastDayOfMonth() + ' 23:59:59',
                            operate: 'RANGE',
                            visible: false,
                            addclass: 'datetimerange'
                        }

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        select: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'basic/goods/select' + location.search,
                    // add_url: 'basic/goods/add',
                    // edit_url: 'basic/goods/edit',
                    // del_url: 'basic/goods/del',
                    multi_url: 'basic/goods/multi',
                    import_url: 'basic/goods/import',
                    table: 'goods',
                    dragsort_url: "",
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: false,
                fixedRightNumber: 1,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'category_id', title: __('商品类'),
                            searchList: $.getJSON("basic/goods/getCategory")
                        },
                        {field: 'sku', title: __('规格'), operate: 'LIKE'},
                        {field: 'number', title: __('Number'), operate: 'LIKE'},
                        {field: 'cost_price', title: __(' 成本价'), operate: 'LIKE'},
                        {field: 'retail_price', title: __('零售价'), operate: 'LIKE'},
                        {
                            field: 'qty',
                            title: __('库存'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'use',
                                    text: __('选择'),
                                    title: __('选择'),
                                    classname: 'btn btn-xs btn-warning btn-click',
                                    click: function (e, row) {
                                        //获取选中的id，获取到的是个数组
                                        Fast.api.close(row);//这里是重点，将这个ids 传至父页面
                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'basic/goods/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'basic/goods/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'basic/goods/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },

        qty_log: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'basic/goods/qty_log' + location.search,
                    // add_url: 'basic/goods/add',
                    // edit_url: 'basic/goods/edit',
                    // del_url: 'basic/goods/del',
                    multi_url: 'basic/goods/multi',
                    import_url: 'basic/goods/import',
                    table: 'goods',
                    dragsort_url: "",
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: false,
                fixedRightNumber: 1,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'stash_name', title: __('仓库'), operate: false},
                        {
                            field: 'goods.number',
                            title: __('商品编号'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'status',
                            title: __('类型'),
                            searchList: {
                                "100": __('销售单'),
                                "200": __('销售退货单'),
                                "300": __('零售单'),
                                "400": __('进货单'),
                                "500": __('进货退货单'),
                                "1100": __('调拨单(出)'),
                                "1200": __('调拨单(入)'),
                                "1400": __('其他入库单'),
                                "1500": __('其他出库单'),
                                "10000": __('系统删除销售单'),
                                "20000": __('系统删除销售退货单'),
                                "40000": __('系统删除进货单'),
                                "50000": __('系统删除退货单'),
                                "14000": __('系统删除其他入库单'),
                                "15000": __('系统删除其他出库单'),
                            },
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'goods.name',
                            title: __('Name'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'order_no', title: __('单据号')
                        },
                        {field: 'qty', title: __('操作库存'), operate: false},
                        // {field: 'surplus_qty', title: __('剩余库存'), operate: false},
                        {
                            field: 'price',
                            title: __('单价'),
                            operate: false,
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },

                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },

                        // {
                        //     field: 'operate', title: __('Operate'), table: table,
                        //     events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                        //     buttons: [
                        //         {
                        //             name: 'use',
                        //             text: __('选择'),
                        //             title: __('选择'),
                        //             classname: 'btn btn-xs btn-warning btn-click',
                        //             icon: 'fa fa-folder-o',
                        //             click:function(e,row){
                        //                 //获取选中的id，获取到的是个数组
                        //                 Fast.api.close(row);//这里是重点，将这个ids 传至父页面
                        //             }
                        //         }
                        //     ]
                        // }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        }
        ,
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },

        getFirstDayOfMonth: function getFirstDayOfMonth() {
            const currentDate = new Date();
            const firstDay = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
            return this.formatDate(firstDay)
        },
        getLastDayOfMonth: function getLastDayOfMonth() {
            const currentDate = new Date();
            const lastDay = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
            return this.formatDate(lastDay);
        },
        formatDate: function formatDate(date) {
            const year = date.getFullYear();
            const month = ("0" + (date.getMonth() + 1)).slice(-2);
            const day = ("0" + date.getDate()).slice(-2);
            return year + "-" + month + "-" + day;
        }

    };

    return Controller;
});
